package com.timoon.component.panel.highcharts;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;

import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.app.utils.GlobalRandom;
import com.timoon.component.behavior.highcharts.HighChartsBehavior;
import com.timoon.component.panel.highcharts.parameter.HighChartsPieParameter;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

public class PiePanel extends Panel {

	public PiePanel(String id,HighChartsPieParameter parameter) {
		super(id);
		// TODO Auto-generated constructor stub
		WebMarkupContainer pie=new WebMarkupContainer("wk_highcharts_pie");
		add(pie);
		//生成随机id
		String containerID="highcharts_container_"+GlobalRandom.getRandom();
		pie.add(new AttributeModifier("id", containerID));
		
		Options ops=new Options();
		ops.set("chart","{plotBackgroundColor: "+parameter.getChart_plotBackgroundColor()+",plotBorderWidth: "+parameter.getChart_plotBorderWidth()+",plotShadow: "+parameter.getChart_plotShadow()+"}");
		
		ops.set("title", "{text: "+parameter.getTitle_text()+"}");
		
		ops.set("plotOptions", "{pie: { allowPointSelect: "+parameter.getPlotOptions_pie_allowPointSelect()+", cursor: "+parameter.getPlotOptions_pie_cursor()+",dataLabels: {enabled: "+parameter.getPlotOptions_pie_dataLabels_enabled()+",color: "+parameter.getPlotOptions_pie_dataLabels_color()+",connectorColor: "+parameter.getPlotOptions_pie_dataLabels_connectorColor()+", formatter: function()  {"+parameter.getPlotOptions_pie_dataLabels_formatter()+"}} }}");
		
		ops.set("series","[{type: "+parameter.getSeries_type()+", name:"+parameter.getSeries_name()+",data: "+parameter.getSeries_data()+"}] ");
		
		ops.set("tooltip", "{pointFormat:"+parameter.getTooltip_pointFormat()+",percentageDecimals: "+parameter.getTooltip_percentageDecimals()+"}");
		
		pie.add(new HighChartsBehavior("#"+containerID,ops));
	}

}
